﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Text;
using WebExam.Core.Repository;

namespace WebExam.DataEntities
{
    [Table(Name = "dbo.ZY")]
    public partial class ZY : Entity
    {

        private decimal _zyNum;

        private decimal _yxNum;

        private string _zxkm;

        private string _zyName;

        private bool _zyZF;

        private EntitySet<BJ> _BJ;

        private EntityRef<YX> _YX;

        public ZY()
        {
            this._BJ = new EntitySet<BJ>(new Action<BJ>(this.attach_BJ), new Action<BJ>(this.detach_BJ));
            this._YX = default(EntityRef<YX>);
        }

        [Column(Storage = "_zyNum", AutoSync = AutoSync.OnInsert, DbType = "Decimal(18,0) NOT NULL IDENTITY", IsPrimaryKey = true, IsDbGenerated = true)]
        public decimal ZYNum
        {
            get
            {
                return this._zyNum;
            }
            set
            {
                if ((this._zyNum != value))
                {
                    this.SendPropertyChanging("ZYNum");
                    this._zyNum = value;
                    this.SendPropertyChanged("ZYNum",value);
                }
            }
        }

        [Column(Storage = "_yxNum", DbType = "Decimal(18,0)")]
        public decimal YXNum
        {
            get
            {
                return this._yxNum;
            }
            set
            {
                if ((this._yxNum != value))
                {
                    if (this._YX.HasLoadedOrAssignedValue)
                    {
                        throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
                    }
                    this.SendPropertyChanging("YXNum");
                    this._yxNum = value;
                    this.SendPropertyChanged("YXNum",value);
                }
            }
        }

        [Column(Storage = "_zxkm", DbType = "VarChar(1000)")]
        public string ZXKM
        {
            get
            {
                return this._zxkm;
            }
            set
            {
                if ((this._zxkm != value))
                {
                    this.SendPropertyChanging("ZXKM");
                    this._zxkm = value;
                    this.SendPropertyChanged("ZXKM",value);
                }
            }
        }

        [Column(Storage = "_zyName", DbType = "VarChar(30) NOT NULL", CanBeNull = false)]
        public string ZYName
        {
            get
            {
                return this._zyName;
            }
            set
            {
                if ((this._zyName != value))
                {
                    this.SendPropertyChanging("ZYName");
                    this._zyName = value;
                    this.SendPropertyChanged("ZYName",value);
                }
            }
        }

        [Column(Storage = "_zyZF", DbType = "Bit")]
        public bool ZYZF
        {
            get
            {
                return this._zyZF;
            }
            set
            {
                if ((this._zyZF != value))
                {
                    this.SendPropertyChanging("ZYZF");
                    this._zyZF = value;
                    this.SendPropertyChanged("ZYZF",value);
                }
            }
        }

        [Association(Name = "ZY_BJ", Storage = "_BJ", ThisKey = "ZYNum", OtherKey = "ZYNum")]
        public EntitySet<BJ> BJ
        {
            get
            {
                return this._BJ;
            }
            set
            {
                this._BJ.Assign(value);
            }
        }

        [Association(Name = "YX_ZY", Storage = "_YX", ThisKey = "YXNum", OtherKey = "YXNum", IsForeignKey = true)]
        public YX YX
        {
            get
            {
                return this._YX.Entity;
            }
            set
            {
                YX previousValue = this._YX.Entity;
                if (((previousValue != value)
                            || (this._YX.HasLoadedOrAssignedValue == false)))
                {
                    this.SendPropertyChanging("YX");
                    if ((previousValue != null))
                    {
                        this._YX.Entity = null;
                        previousValue.ZY.Remove(this);
                    }
                    this._YX.Entity = value;
                    if ((value != null))
                    {
                        value.ZY.Add(this);
                        this._yxNum = value.YXNum;
                    }
                    else
                    {
                        this._yxNum = default(decimal);
                    }
                    this.SendPropertyChanged("YX",value);
                }
            }
        }

        private void attach_BJ(BJ entity)
        {
            entity.ZY = this;
        }

        private void detach_BJ(BJ entity)
        {
            entity.ZY = null;
        }
    }
}
